<!--
 * @Author: your name
 * @Date: 2020-02-25 13:32:39
 * @LastEditTime: 2020-02-28 11:25:55
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \福路德扫码系统\html\cksm.html
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../../css/local.css" />
    <link rel="stylesheet" type="text/css" href="../../font/iconfont.css" />
    <link rel="stylesheet" href="../../script/elementui/lib/theme-chalk/index.css?t=1">
    <link href="../../script/elementui/vue-element-table.css" rel="stylesheet" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script src="../../script/elementui/lib/index.js?t=1"></script>
    <script src="../../script/elementui/vue-element-bigdata-table.min.js?t=4"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <script type="text/javascript" src="../../script/JSLINQ.js"></script>
    <style type="text/css">
        .select-date {
            border-bottom: 3px solid #efefef;
        }

        .event {
            color: #000;
            padding-bottom: 5px;
            font-size: 15px;
        }

        .time {
            font-size: 13px;
        }

        .date {
            padding: 10px;
            font-weight: 700;
            font-size: 16px;
            color: #1daaff;
        }

        .np {
            padding: 0;
        }

        .module {
            padding: 8px 10px 0 10px;
        }

        .module>div {
            background: #fff;
            padding: 8px;
            border-radius: 8px;
            overflow: hidden;
        }

        .label {
            color: #969799;
        }

        .navigateUrl {
            color: #2b68f1;
            text-decoration: underline;
        }

        .imgUrl,
        .videoUrl {
            color: #2b68f1;
        }

        .van-loading {
            position: fixed;
            top: 50%;
            z-index: 99999;
            left: calc(50% - 20px);
        }

        .el-table-green {
            color: green;
        }

        .el-table-red {
            color: red;
        }

        .el-table-yellow {
            color: yellow;
        }

        .el-table-blue {
            color: blue;
        }

        .el-table-white {
            color: white;
        }

        .bold {
            font-weight: bold;
            text-decoration: none !important;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-nav-bar-main :title="titleName" left-arrow @click-left="onClickLeft">
                <div slot="right">
                    <span @click="showSearch = true;">
                        <van-icon name="search" size="18px"></van-icon>
                    </span>
                </div>
            </van-nav-bar-main>
            <div class="content report-table">
                <!-- <el-table :data="tableData" style="width: 100%">
                    <el-table-column prop="BillDate" label="日期" width="180">
                    </el-table-column>
                    <el-table-column prop="ProductName" label="姓名" width="180">
                    </el-table-column>
                    <el-table-column prop="ProcedureName" label="地址">
                    </el-table-column>
                </el-table> -->
                <el-bigdata-table class="mainTable" ref="mainTable" :height="tableHeight" :data="tableData"
                    :span-method="rowSpanMethod" :width="tableWidth" :stripe="true" border :highlight-current-row="true"
                    :row-class-name="setRowClass" :cell-class-name="cellClassName" @cell-click="cellClick"
                    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                    <el-table-column v-for="column in column_config" :label="column.label" :prop="column.name"
                        :width="column.width" sortable :fixed="column.isFrozen==1" v-if="isShowCheckCol(column.name)">
                        <template slot-scope="scope">
                            <div v-if="scope.row[column.name] && scope.row[column.name].toString().indexOf('img:')>=0 ">
                                <span class="iconfont icon-tuwenxiangqing"
                                    v-if="scope.row[column.name].toString().split(':')[1]"
                                    @click="openMedia(scope.row[column.name].toString().split(':')[1],1)"></span>
                            </div>
                            <div
                                v-else-if="scope.row[column.name] && scope.row[column.name].toString().indexOf('video:')>=0 ">
                                <span class="iconfont icon-shipin"
                                    v-if="scope.row[column.name].toString().split(':')[1]"
                                    @click="openMedia(scope.row[column.name].toString().split(':')[1],2)"></span>
                            </div>
                            <div
                                v-else-if="scope.row[column.name] && scope.row[column.name].toString().indexOf('office:')>=0 ">
                                <span class="iconfont icon-shipin"
                                    v-if="scope.row[column.name].toString().split(':')[1]"
                                    @click="openMedia(scope.row[column.name].toString().split(':')[1],3)"></span>
                            </div>
                            <div v-else :title="setTitle(scope.row[column.name])">
                                {{scope.row[column.name]}}
                            </div>
                        </template>
                        <el-table-column v-for="column_sub1 in column.subColumn" :label="column_sub1.label"
                            :prop="column_sub1.name" :width="column_sub1.width" sortable :fixed="column.isFrozen==1"
                            v-if="isShowCheckCol(column_sub1.name)">
                            <template slot-scope="scope">
                                <div
                                    v-if="scope.row[column_sub1.name] && scope.row[column_sub1.name].toString().indexOf('img:')>=0 ">
                                    <span class="iconfont icon-tuwenxiangqing"
                                        v-if="scope.row[column_sub1.name].toString().split(':')[1]"
                                        @click="openMedia(scope.row[column_sub1.name].toString().split(':')[1],1)"></span>
                                </div>
                                <div
                                    v-else-if="scope.row[column_sub1.name] && scope.row[column_sub1.name].toString().indexOf('video:')>=0 ">
                                    <span class="iconfont icon-shipin"
                                        v-if="scope.row[column_sub1.name].toString().split(':')[1]"
                                        @click="openMedia(scope.row[column_sub1.name].toString().split(':')[1],2)"></span>
                                </div>
                                <div
                                    v-else-if="scope.row[column_sub1.name] && scope.row[column_sub1.name].toString().indexOf('office:')>=0 ">
                                    <span class="iconfont icon-shipin"
                                        v-if="scope.row[column_sub1.name].toString().split(':')[1]"
                                        @click="openMedia(scope.row[column_sub1.name].toString().split(':')[1],3)"></span>
                                </div>
                                <div v-else :title="setTitle(scope.row[column_sub1.name])">
                                    {{scope.row[column_sub1.name]}}
                                </div>
                            </template>
                            <el-table-column v-for="column_sub2 in column_sub1.subColumn" :label="column_sub2.label"
                                :prop="column_sub2.name" :width="column_sub2.width" sortable :fixed="column.isFrozen==1"
                                v-if="isShowCheckCol(column_sub2.name)">
                                <template slot-scope="scope">
                                    <div
                                        v-if="scope.row[column_sub2.name] && scope.row[column_sub2.name].toString().indexOf('img:')>=0 ">
                                        <span class="iconfont icon-tuwenxiangqing"
                                            v-if="scope.row[column_sub2.name].toString().split(':')[1]"
                                            @click="openMedia(scope.row[column_sub2.name].toString().split(':')[1],1)"></span>
                                    </div>
                                    <div
                                        v-else-if="scope.row[column_sub2.name] && scope.row[column_sub2.name].toString().indexOf('video:')>=0 ">
                                        <span class="iconfont icon-shipin"
                                            v-if="scope.row[column_sub2.name].toString().split(':')[1]"
                                            @click="openMedia(scope.row[column_sub2.name].toString().split(':')[1],2)"></span>
                                    </div>
                                    <div
                                        v-else-if="scope.row[column_sub2.name] && scope.row[column_sub2.name].toString().indexOf('office:')>=0 ">
                                        <span class="iconfont icon-shipin"
                                            v-if="scope.row[column_sub2.name].toString().split(':')[1]"
                                            @click="openMedia(scope.row[column_sub2.name].toString().split(':')[1],3)"></span>
                                    </div>
                                    <div v-else :title="setTitle(scope.row[column_sub2.name])">
                                        {{scope.row[column_sub2.name]}}
                                    </div>
                                </template>
                                <el-table-column v-for="column_sub3 in column_sub2.subColumn" :label="column_sub3.label"
                                    :prop="column_sub3.name" :width="column_sub3.width" sortable
                                    :fixed="column.isFrozen==1" v-if="isShowCheckCol(column_sub3.name)">
                                    <template slot-scope="scope">
                                        <div
                                            v-if="scope.row[column_sub3.name] && scope.row[column_sub3.name].toString().indexOf('img:')>=0 ">
                                            <span class="iconfont icon-tuwenxiangqing"
                                                v-if="scope.row[column_sub3.name].toString().split(':')[1]"
                                                @click="openMedia(scope.row[column_sub3.name].toString().split(':')[1],1)"></span>
                                        </div>
                                        <div
                                            v-else-if="scope.row[column_sub3.name] && scope.row[column_sub3.name].toString().indexOf('video:')>=0 ">
                                            <span class="iconfont icon-shipin"
                                                v-if="scope.row[column_sub3.name].toString().split(':')[1]"
                                                @click="openMedia(scope.row[column_sub3.name].toString().split(':')[1],2)"></span>
                                        </div>
                                        <div
                                            v-else-if="scope.row[column_sub3.name] && scope.row[column_sub3.name].toString().indexOf('office:')>=0 ">
                                            <span class="iconfont icon-shipin"
                                                v-if="scope.row[column_sub3.name].toString().split(':')[1]"
                                                @click="openMedia(scope.row[column_sub3.name].toString().split(':')[1],3)"></span>
                                        </div>
                                        <div v-else :title="setTitle(scope.row[column_sub3.name])">
                                            {{scope.row[column_sub3.name]}}
                                        </div>
                                    </template>
                                    <el-table-column v-for="column_sub4 in column_sub3.subColumn"
                                        :label="column_sub4.label" :prop="column_sub4.name" :width="column_sub4.width"
                                        sortable :fixed="column.isFrozen==1" v-if="isShowCheckCol(column_sub4.name)">
                                        <template slot-scope="scope">
                                            <div
                                                v-if="scope.row[column_sub4.name] && scope.row[column_sub4.name].toString().indexOf('img:')>=0 ">
                                                <span class="iconfont icon-tuwenxiangqing"
                                                    v-if="scope.row[column_sub4.name].toString().split(':')[1]"
                                                    @click="openMedia(scope.row[column_sub4.name].toString().split(':')[1],1)"></span>
                                            </div>
                                            <div
                                                v-else-if="scope.row[column_sub4.name] && scope.row[column_sub4.name].toString().indexOf('video:')>=0 ">
                                                <span class="iconfont icon-shipin"
                                                    v-if="scope.row[column_sub4.name].toString().split(':')[1]"
                                                    @click="openMedia(scope.row[column_sub4.name].toString().split(':')[1],2)"></span>
                                            </div>
                                            <div
                                                v-else-if="scope.row[column_sub4.name] && scope.row[column_sub4.name].toString().indexOf('office:')>=0 ">
                                                <span class="iconfont icon-shipin"
                                                    v-if="scope.row[column_sub4.name].toString().split(':')[1]"
                                                    @click="openMedia(scope.row[column_sub4.name].toString().split(':')[1],3)"></span>
                                            </div>
                                            <div v-else :title="setTitle(scope.row[column_sub4.name])">
                                                {{scope.row[column_sub4.name]}}
                                            </div>
                                        </template>
                                    </el-table-column>
                                </el-table-column>
                            </el-table-column>
                        </el-table-column>
                    </el-table-column>
                </el-bigdata-table>
                <div>
                    <div style="width:100%;overflow:hidden;border-left: 1px solid #EBEEF5;" id="summaryData">
                        <table v-if="tableData.length" id="summaryFoot">
                            <tr>
                                <th v-for="(row,index) in summaryData">
                                    <div>{{row}}</div>
                                </th>
                            </tr>
                            <tr v-for="subRow in calSubDatas">
                                <th v-for="(srow,sIndex) in subRow.data">
                                    <div>{{ srow }}</div>
                                </th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <van-popup v-model="showSearch" position="bottom">
            <div class="bottom-search">
                <van-row v-for="(row,index) in searchList" v-if="row.baseProperty.labelName">
                    <van-col span="24" v-if="row.baseProperty.controlType == 'datepicker'">
                        <van-field :required="row.baseProperty.isRequired" readonly v-model="row.baseProperty.showValue"
                            :label="row.baseProperty.labelName" right-icon="arrow" @click="openDate(row,index)">
                        </van-field>
                    </van-col>
                    <van-col span="24" v-if="row.baseProperty.controlType == 'textbox'">
                        <van-field :required="row.baseProperty.isRequired" :readonly="row.baseProperty.isReadOnly"
                            v-model="formData[row.baseProperty.controlName]" :label="row.baseProperty.labelName"
                            placeholder="请输入...">
                        </van-field>
                    </van-col>
                    <van-col span="24"
                        v-if="row.baseProperty.controlType == 'select' && row.controlProperty.select.type == 1">
                        <van-field :required="row.baseProperty.isRequired" readonly v-model="row.baseProperty.showValue"
                            :label="row.baseProperty.labelName" placeholder="请选择" @click="openSelect(row,index)">
                        </van-field>
                    </van-col>
                </van-row>

            </div>
            <div class="btn-padding">
                <van-button color="#83bff6" type="primary" block style="border-radius: 0;" @click="searchReport">查询
                </van-button>
            </div>
        </van-popup>
        <van-popup v-model="showDate" position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" @confirm="confirmDate" @cancel="cancelDate"
                cancel-button-text="取消" />
        </van-popup>

        <van-popup v-model="showSelect" position="bottom">
            <van-picker show-toolbar :columns="selectColumns" :loading="selectLoading" :value-key="selectValueKey"
                @confirm="confirmSelect" @cancel="cancelSelect"></van-picker>
        </van-popup>
        <van-image-preview v-model="showImg" :images="showImgList">
        </van-image-preview>

        <van-loading size="24px" vertical>加载中...</van-loading>
    </div>
</body>
<script type="text/javascript">
    var vm;
    var editIndex = '';


    apiready = function () {

        var office = api.require('officePreview');
        var docReader = api.require('docReader');

        // api.setScreenOrientation({
        //     orientation: 'landscape_left'
        // });

        api.addEventListener({
            name: 'refreshMainReport'
        }, function (ret) {
            vm.searchReport();
        })

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '产品') {
                if (!row) {
                    vm.searchData.ProductID = '';
                    vm.searchData.ProductName = '';
                } else {
                    vm.searchData.ProductID = row[0].ProductID;
                    vm.searchData.ProductName = row[0].ProductName;
                }
            }
            if (type == '销售订单') {
                if (!row) {
                    vm.searchData.SoOrderID = '';
                    vm.searchData.SoOrderName = '';
                } else {
                    vm.searchData.SoOrderID = row[0].SoOrderID;
                    vm.searchData.SoOrderName = row[0].Billno;
                }

            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                titleName: '', //api.pageParam.titleName,
                showSearch: false,
                dataList: [],
                currentDate: new Date(),
                showDate: false,
                searchList: [],
                searchData: {
                    ProductName: '',
                    ProductID: '',
                    SoOrderName: '',
                    SoOrderID: '',
                    FBdate: APP.getFormatDate2('yyyy-MM-dd', new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 30)),
                    FEdate: APP.getFormatDate2('yyyy-MM-dd')
                },
                showSelect: false,
                selectLoading: false,
                selectColumns: [],
                selectValueKey: '',
                selectRealKey: '',
                showImg: false,
                showImgList: [],

                columns: [],
                tableData: [],
                summaryData: [],
                subSummaryData: [],
                subColTotal: '',
                childFormList: [],
                formDesign: [],
                formData: {},
                sql: "",
                report_title: "",
                report_subtitle: "",
                column_originConfig: [],
                column_config: [],
                showSummary: false,
                rowClassCol: "",
                colClassCol: "",
                searchCallBack: "",
                tableWidth: 0,

                params: {},
                workList: [],
                crudList: [],
                headerFilter: [],
                tableHeight: 0,
                queryFilter: {},
                loading: null,
                currentColName: '',
                currentClickRow: {},
                paging: {
                    pageSize: 30,
                    pageIndex: 0,
                    totalCount: 0
                },
                crud: {
                    create: [],
                    update: [],
                    delete: []
                },
                selections: [],
                filterTags: [],
                isShiftKeyDown: false,
                batchUpdateDialog: false,
                batchUpdateColName: '',
                batchUpdateCol: {},
                batchUpdateVal: '',
                selectTableData: [],
                selectTableOriginData: [],
                selectColumns: [],
                selectTableColIndex: -1,
                selectTableTarget: undefined,
                selectTableSearchKey: "",
                selectTableVisible: false,
                isInitCal: false,
                isSubInitCal: false,
                calDatas: [],
                calSubDatas: [],
                searchParam: [],
                currentRowData: {},
                reportWindowIndex: '',
                chartConfig: [],
                //显示列对象
                showColumns: [],
                rowKey: '',
                //行列合并函数
                spanMethodFunc: '',
                summaryColumnData: [],
                appendNum: 500

            },
            created: function () {
                var that = this;
                that.tableWidth = window.innerWidth;
                tableConfig.initConfig(api.pageParam.moduleName);
                that.layoutPage();
            },
            methods: {
                post(sql, param, callBack) {
                    param["sql"] = sql;
                    $.ajax({
                        url: APP.serverIP() + "/SQLData/QuerySql",
                        type: "post",
                        dataType: "json",
                        async: false,
                        data: param,
                        success: function (data) {
                            if (data.status == 200) {
                                callBack(data.data);
                            } else {
                                //console.log(JSON.stringify(layer));
                                layer.alert(data.msg);
                            }
                        }
                    });
                    //vm.handleSizeChange(vm.paging.pageIndex);
                },
                setTitle(str) {
                    if (str) {
                        return str.toString().replace(/\n|\r/g, "").replace(/<\/?.+?>/g, "").replace(/\ +/g, "");
                    } else {
                        return str;
                    }
                },
                //布局页面
                layoutPage() {
                    var that = this;
                    that.tableHeight = window.innerHeight - 100;
                    that.tableWidth = window.innerWidth;
                },
                headerDragend(newWidth, oldWidth, column, event) {
                    setTimeout(function () {

                        $('#summaryFoot').width($('.el-table__body tbody tr').width() + 'px')
                        $('#summaryFoot th').each(function (index) {
                            $(this).find('div').width($('.el-table__body tbody tr td').eq(index).width() + 'px')
                        })
                    }, 200)
                },
                //打开Loading
                openLoading() {
                    $(".van-loading").show();
                    // if (vm.loading != null) {
                    //     vm.loading.close();
                    // }
                    // vm.loading = vm.$loading({
                    //     lock: true,
                    //     text: '正在加载数据',
                    //     spinner: 'el-icon-loading',
                    //     background: 'rgba(0, 0, 0, 0.7)',
                    //     target: document.querySelector('.vue-element-bigdata-table')
                    // });
                },
                closeLoading() {
                    $(".van-loading").hide();
                    // setTimeout(function() {
                    //     vm.loading.close();
                    // }, 200);
                },
                controlInit: function () {

                    //控件属性赋值
                    for (var i = 0; i < vm.formDesign.length; i++) {
                        for (var j = 0; j < vm.formDesign[i].controls.length; j++) {
                            var controlNo = vm.formDesign[i].controls[j].baseProperty.controlNo;
                            if (vm.formDesign[i].controls[j].baseProperty.controlNo)
                                var currentDom = $("[controlNo='" + controlNo + "']");
                            if (vm.formDesign[i].controls[j].baseProperty.controlType == 'datepicker') {
                                currentDom = $("[controlNo='" + controlNo + "']").children(":first");
                            } else if (vm.formDesign[i].controls[j].baseProperty.controlType == 'select' && vm.formDesign[i].controls[j].controlProperty.select.type == 1) {
                                currentDom = $("[controlNo='" + controlNo + "']").children(":first").children(":first");
                            }
                            currentDom.attr("style", vm.formDesign[i].controls[j].controlProperty.css);
                            var othersObj = vm.formDesign[i].controls[j].controlProperty.others;
                            //按逗号隔开属性
                            for (var k = 0; k < othersObj.split(',').length; k++) {
                                var objProperty = othersObj.split(',')[k];
                                if (objProperty.split('=').length == 2) {
                                    currentDom.attr(objProperty.split('=')[0], objProperty.split('=')[1]);
                                }
                            }
                            //必填项选择
                            if (vm.formDesign[i].controls[j].baseProperty.isRequired) {
                                currentDom.css({
                                    background: '#f8f9dd'
                                });
                            } else {
                                currentDom.css({
                                    background: '#ffffff'
                                });
                            }
                        }
                    }
                },
                //验证必填项
                valitedRequired() {
                    var resultObj = {
                        status: 200,
                        msg: ""
                    };
                    for (var i = 0; i < vm.searchList.length; i++) {
                        if (vm.searchList[i].baseProperty.isRequired && !vm.searchList[i].baseProperty.value) {
                            resultObj = {
                                status: 500,
                                msg: vm.searchList[i].baseProperty.labelName + "字段不能为空!"
                            };
                        }
                    }
                    return resultObj;
                },
                //报表查询
                searchReport() {
                    //验证必填项
                    var valitedResult = vm.valitedRequired();
                    if (valitedResult.status == 500) {
                        layer.alert(valitedResult.msg);
                        return;
                    } else {
                        vm.showSearch = false;
                        vm.isInitCal = false;
                        vm.isSubInitCal = false;
                        vm.openLoading();
                        var searchParam = [];

                        for (var key in vm.formData) {
                            var formValue = vm.formData[key];
                            if (!formValue) {
                                formValue = "";
                            }
                            if (typeof formValue == "object" && formValue.constructor == Array) {
                                formValue = formValue.join(',');
                            }
                            searchParam.push({
                                Key: key,
                                Value: formValue
                            })
                        }

                        for (var key in api.pageParam) {
                            var formValue = api.pageParam[key];
                            if (!formValue) {
                                formValue = "";
                            }
                            if (typeof formValue == "object" && formValue.constructor == Array) {
                                formValue = formValue.join(',');
                            }
                            searchParam.push({
                                Key: key,
                                Value: formValue
                            })
                        }

                        //console.log(JSON.stringify(searchParam))
                        $.ajax({
                            url: APP.serverIP() + "/SQLData/GetDataBySql",
                            async: false,
                            data: {
                                sql: vm.sql,
                                sqlParam: searchParam
                            },
                            type: "post",
                            timeout: 1000 * 60 * 5, //超时时间：5分钟
                            dataType: 'json',
                            success: function (data) {
                                console.log(JSON.stringify(data));
                                if (data.status == 200) {
                                    //主页标题和附标题
                                    if (data.data.ds != undefined && data.data.ds.length > 0) {
                                        vm.titleName = data.data.ds[0].title;
                                        //vm.report_subtitle = data.data.ds[0].subtitle;
                                        if (data.data.ds[0].treereport == 1) {
                                            vm.rowKey = data.data.ds[0].mainKey;
                                        }


                                    }
                                    //列配置
                                    if (data.data.ds1 != undefined && data.data.ds1.length > 0) {
                                        // let isUpdateShowColumns = true;
                                        // if (vm.showColumns.length > 0) {
                                        //     isUpdateShowColumns = false;
                                        // }
                                        vm.column_originConfig = data.data.ds1;
                                        vm.column_config = JSLINQ(data.data.ds1).where(function (item) {
                                            return item.parentName == ""
                                        }).ToArray();

                                        for (var i = 0; i < vm.column_config.length; i++) {
                                            // if (isUpdateShowColumns) {
                                            //     vm.showColumns.push(vm.column_config[i].name);
                                            // }
                                            if (vm.column_config[i].total != "") {
                                                vm.showSummary = true;
                                            }
                                            vm.column_config[i].subColumn = vm.getSubColumn(data.data.ds1, vm.column_config[i].name);
                                            // for (var j = 0; j < vm.column_config[i].subColumn.length; j++) {
                                            //     if (isUpdateShowColumns) {
                                            //         vm.showColumns.push(vm.column_config[i].subColumn[j].name);
                                            //     }
                                            // }
                                        }
                                        // vm.$nextTick(function() {
                                        //     vm.tableHeight = 500; //document.getElementsByClassName("report-table")[0].offsetHeight;
                                        // })

                                    }
                                    //合计行数据
                                    if (data.data.ds3 != undefined && data.data.ds3.length > 0) {
                                        vm.summaryColumnData = data.data.ds3;
                                    }
                                    //数据源配置
                                    if (data.data.ds2 != undefined && data.data.ds2.length > 0) {
                                        //console.log(JSON.stringify(data.data.ds2))
                                        if (!vm.rowKey) {
                                            vm.tableData = data.data.ds2;
                                        } else {
                                            vm.tableData = JSLINQ(data.data.ds2).where(function (item) {
                                                return item[data.data.ds[0].subKey].toString() == "0"
                                            }).ToArray();
                                            for (var i = 0; i < vm.tableData.length; i++) {
                                                let children = JSLINQ(data.data.ds2).where(function (item) {
                                                    return vm.tableData[i][data.data.ds[0].mainKey] == item[data.data.ds[0].subKey]
                                                }).ToArray();
                                                if (children.length > 0) {
                                                    //vm.$set(vm.tableData[i], "hasChildren", true);
                                                    vm.setLeafNode(children, data.data.ds2, data.data.ds[0].mainKey, data.data.ds[0].subKey);
                                                    vm.$set(vm.tableData[i], "children", children);
                                                }
                                            }
                                        }
                                        var colProperty = {
                                            columns: []
                                        };
                                        if (data.data.ds2.length > 0) {
                                            var repeatColumn = function (array) {
                                                for (var i in array) {
                                                    if (array[i].subColumn.length) {
                                                        repeatColumn(array[i].subColumn)
                                                    } else {
                                                        colProperty.columns.push({
                                                            property: array[i].name
                                                        });
                                                    }
                                                }
                                            }
                                            repeatColumn(vm.column_config)

                                            vm.summaryData = vm.getSummaries(colProperty);
                                            var subTotalObj = JSLINQ(vm.column_config).where(function (item) {
                                                return item.isSubTotal == 1
                                            }).ToArray();
                                            if (subTotalObj.length > 0) {
                                                vm.subColTotal = subTotalObj[0].name;
                                                vm.subSummaryData = vm.getSubSummaries(colProperty);
                                            }


                                            vm.$nextTick(function () {
                                                setTimeout(function () {
                                                    $('#summaryFoot').width($('.el-table__body tbody tr').width() + 'px')
                                                    for (var i in vm.summaryData) {
                                                        $('#summaryFoot th').eq(i).find('div').width($('.el-table__body tbody tr td').eq(i).width() + 'px');
                                                    }
                                                }, 300);

                                                //vm.tableHeight = 500; //document.getElementsByClassName("report-table")[0].offsetHeight;
                                                //vm.tableHeight = window.innerHeight - $('#reporthead').height() - $('#summaryData').height() - 32;
                                            })
                                        }
                                        JSON.stringify(vm.tableData)
                                    } else {
                                        vm.tableData = [];
                                    }
                                    if (vm.searchCallBack) {
                                        eval(vm.searchCallBack);
                                    }
                                }
                                vm.closeLoading();
                            }
                        });
                    }
                },
                setLeafNode(childrenObj, sourceObj, mainKey, subKey) {
                    for (var i = 0; i < childrenObj.length; i++) {
                        let children = JSLINQ(sourceObj).where(function (item) {
                            return childrenObj[i][mainKey] == item[subKey]
                        }).ToArray();
                        if (children.length > 0) {
                            //vm.$set(vm.tableData[i], "hasChildren", true);
                            vm.setLeafNode(children, sourceObj, mainKey, subKey);
                            childrenObj[i].children = children;
                            //vm.$set(vm.tableData[i], "children", children);
                        }
                    }
                },
                cellClassName(row) {
                    var column = row.column;
                    var styleName = "";
                    var currentColumnConfig = JSLINQ(vm.column_originConfig).where(function (item) {
                        return item.label == column.label
                    }).ToArray();

                    if (column.property) {
                        currentColumnConfig = JSLINQ(currentColumnConfig).where(function (item) {
                            return item.name == column.property
                        }).ToArray();
                    }



                    if (currentColumnConfig.length > 0) {
                        if (currentColumnConfig[0].url) {
                            styleName = "navigateUrl";
                        }
                        if ((row.row[currentColumnConfig[0].name] + '').indexOf('file:') >= 0) {
                            styleName = "navigateUrl";
                        }
                        if ((row.row[currentColumnConfig[0].name] + '').indexOf('img:') >= 0) {
                            styleName = "imgUrl";
                        }
                        if ((row.row[currentColumnConfig[0].name] + '').indexOf('video:') >= 0) {
                            styleName = "videoUrl";
                        }
                    }

                    if (vm.colClassCol) {
                        debugger;
                        var rowClassEvent = vm.colClassCol.replace(/\['/g, " row.row['")
                        rowClassEvent = rowClassEvent.replace(/\["/g, " row.row[\"");
                        var scriptFun = " function fun(){ " + rowClassEvent + "  }  ";
                        scriptFun += "styleName += fun()  ";
                        eval(scriptFun);
                    }
                    return styleName;
                },
                //更改行样式
                setRowClass(rowData) {
                    var clsName = "";
                    if (vm.rowClassCol) {
                        var rowClassEvent = vm.rowClassCol.replace(/\['/g, " rowData.row['")
                        rowClassEvent = rowClassEvent.replace(/\["/g, " rowData.row[\"");
                        var scriptFun = " function fun(){ " + rowClassEvent + "  }  ";
                        scriptFun += "clsName += fun()  ";
                        eval(scriptFun);
                    }
                    return clsName;
                },
                cellClick(row, column, cell, event) {
                    let cellValue = row[column.property].toString();
                    if (!cellValue) {
                        return;
                    }

                    if (cellValue.indexOf('file:') >= 0) {
                        var url = "/FileData/DownloadFile?filePath=" + cellValue.split(':')[1];
                        var html = '<form action="' + url + '" method="post">';
                        html += "</form>";
                        $(html).appendTo('body').submit().remove();
                    } else if (cellValue.indexOf('img:') >= 0) { } else if (cellValue.indexOf('video:') >= 0) { } else if (cellValue.indexOf('office:') >= 0) { } else {


                        var currentColumnConfig = JSLINQ(vm.column_originConfig).where(function (item) {
                            return item.label == column.label
                        }).ToArray();

                        if (column.property) {
                            currentColumnConfig = JSLINQ(currentColumnConfig).where(function (item) {
                                return item.name == column.property
                            }).ToArray();
                        }

                        if (currentColumnConfig.length > 0) {
                            var pageParam = JSON.parse(JSON.stringify(row));
                            pageParam.subReport = 1;
                            var configUrl = currentColumnConfig[0].url.split('?')[0];
                            if (currentColumnConfig[0].url.indexOf('?') >= 0) {
                                var paramConfigs = currentColumnConfig[0].url.split('?')[1].split('&');
                                for (var i = 0; i < paramConfigs.length; i++) {
                                    pageParam[paramConfigs[i].split('=')[0]] = paramConfigs[i].split('=')[1];
                                }
                            }
                            pageParam.curColName = currentColumnConfig[0].name;
                            pageParam.formData = vm.formData;

                            //console.log(JSON.stringify(pageParam));
                            api.openWin({
                                name: configUrl,
                                url: configUrl,
                                reload: true,
                                slidBackEnabled: false,
                                allowEdit: false,
                                pageParam: pageParam
                            })
                        }
                    }
                },
                closeReportWindow() {
                    layer.close(vm.reportWindowIndex);
                },
                changeRowClass(row) {
                    // if (row.rowIndex == vm.tableData.length - 1) {
                    //     return "totalLevel";
                    // }
                },
                //清除表单数据
                clearFormData(control) {
                    vm.formData[control.baseProperty.controlName] = "";
                    control.controlProperty.select.actualName = "";
                },
                getSubColumn(allData, parentName) {
                    var subColumn = JSLINQ(allData).where(function (item) {
                        return item.parentName == parentName
                    }).ToArray();
                    for (var j = 0; j < subColumn.length; j++) {
                        if (subColumn[j].total != "") {
                            vm.showSummary = true;
                        }
                        subColumn[j].subColumn = vm.getSubColumn(allData, subColumn[j].name);
                    }
                    return subColumn;
                },
                getSummaries(param) {
                    if (vm.isInitCal) {
                        return vm.calDatas;
                    }
                    //合计总数据
                    if (vm.summaryColumnData.length > 0) {
                        var totalData = [];
                        totalData.push("");

                        if (vm.showColumns.length > 0) {
                            let showCols = [];
                            for (var i = 0; i < param.columns.length; i++) {
                                if (JSLINQ(vm.showColumns).where(function (item) {
                                    return item == param.columns[i].property
                                }).ToArray().length > 0) {
                                    showCols.push(param.columns[i]);
                                }
                            }
                            param.columns = showCols;
                        }
                        for (var i = 0; i < param.columns.length; i++) {
                            if (param.columns[i].property == vm.column_originConfig[0].name) {
                                continue;
                            }
                            var subTotalData = "";
                            var current_Column = JSLINQ(vm.column_originConfig).where(function (item) {
                                return item.name == param.columns[i].property
                            }).ToArray()[0];
                            if (current_Column) {
                                if (current_Column.total != "") {
                                    debugger
                                    subTotalData = vm.summaryColumnData[0][current_Column.name]
                                }
                            }

                            totalData.push(subTotalData);
                        }
                        vm.calDatas = totalData;
                        vm.isInitCal = true;

                        if (totalData.join('') == "合计") {
                            return [];
                        }

                        var currentIndex = 0
                        //把合计缩进到最后一个
                        for (var i = 1; i < totalData.length; i++) {
                            if (totalData[i] != "") {
                                currentIndex = i - 1;
                                break;
                            }
                        }
                        totalData[currentIndex] = "合计";



                        return totalData;


                    } else {
                        var totalData = [];
                        totalData.push("");

                        if (vm.showColumns.length > 0) {
                            let showCols = [];
                            for (var i = 0; i < param.columns.length; i++) {
                                if (JSLINQ(vm.showColumns).where(function (item) {
                                    return item == param.columns[i].property
                                }).ToArray().length > 0) {
                                    showCols.push(param.columns[i]);
                                }
                            }
                            param.columns = showCols;
                        }
                        for (var i = 0; i < param.columns.length; i++) {
                            if (param.columns[i].property == vm.column_originConfig[0].name) {
                                continue;
                            }
                            var subTotalData = "";
                            var current_Column = JSLINQ(vm.column_originConfig).where(function (item) {
                                return item.name == param.columns[i].property
                            }).ToArray()[0];
                            if (current_Column) {
                                if (current_Column.total != "") {
                                    //如果是合计类的
                                    if (current_Column.total.indexOf('sum') >= 0) {
                                        if (current_Column.total.indexOf('$') < 0) {
                                            //保留位数
                                            var fixNum = 0;
                                            if (current_Column.total.indexOf(',') >= 0) {
                                                fixNum = parseInt(current_Column.total.split(',')[1]);
                                            }
                                            var totalNum = 0;
                                            for (var j = 0; j < vm.tableData.length; j++) {
                                                var currentNum = parseFloat(vm.tableData[j][current_Column.name]);
                                                if (isNaN(currentNum)) {
                                                    currentNum = 0;
                                                }
                                                totalNum += currentNum;
                                            }
                                            subTotalData = totalNum.toFixed(fixNum);
                                        } else {
                                            var sumPart = current_Column.total.split('$')[0];
                                            //保留位数
                                            var fixNum = 0;
                                            if (sumPart.indexOf(',') >= 0) {
                                                fixNum = parseInt(sumPart.split(',')[1]);
                                            }
                                            var totalNum = 0;
                                            for (var j = 0; j < vm.tableData.length; j++) {
                                                var currentNum = parseFloat(vm.tableData[j][current_Column.name]);
                                                if (isNaN(currentNum)) {
                                                    currentNum = 0;
                                                }
                                                totalNum += currentNum;
                                            }
                                            subTotalData = totalNum.toFixed(fixNum);

                                            var divisorIndex = -1;
                                            for (var k = 0; k < param.columns.length; k++) {
                                                if (param.columns[k].property == current_Column.total.split('$')[1]) {
                                                    divisorIndex = k;
                                                }
                                            }
                                            subTotalData += "(" + (totalNum * 100.0 / totalData[divisorIndex]).toFixed(2) + "%)";
                                        }
                                    } else if (current_Column.total.indexOf('avg') >= 0) {
                                        //保留位数
                                        var fixNum = 0;
                                        if (current_Column.total.indexOf(',') >= 0) {
                                            fixNum = parseInt(current_Column.total.split(',')[1]);
                                        }
                                        var operData = current_Column.total.split(',')[0].substring(current_Column.total.split(',')[0].indexOf('(') + 1, current_Column.total.split(',')[0].indexOf(')'));
                                        var divisorCol = operData.split('/')[0];
                                        var dividendCol = operData.split('/')[1];
                                        var divisorIndex = 0,
                                            dividendIndex = 0;
                                        for (var k = 0; k < param.columns.length; k++) {
                                            if (param.columns[k].property == divisorCol) {
                                                divisorIndex = k;
                                            }
                                            if (param.columns[k].property == dividendCol) {
                                                dividendIndex = k;
                                            }
                                        }
                                        var totalResult = totalData[divisorIndex] / totalData[dividendIndex];
                                        if (current_Column.total.indexOf('%') >= 0) {
                                            totalResult = (totalResult * 100).toFixed(fixNum) + "%";
                                        } else {
                                            totalResult = totalResult.toFixed(fixNum)
                                        }
                                        subTotalData = totalResult;


                                        //var totalNum = 0;
                                        //for (var j = 0; j < vm.tableData.length; j++) {
                                        //    var currentNum = parseFloat(vm.tableData[j][current_Column.name]);
                                        //    if (isNaN(currentNum)) {
                                        //        currentNum = 0;
                                        //    }
                                        //    totalNum += currentNum;
                                        //}
                                        //if (vm.tableData.length > 0) {
                                        //    subTotalData = (totalNum / vm.tableData.length).toFixed(fixNum);
                                        //}
                                        //else {
                                        //    subTotalData = "0";
                                        //}
                                    }
                                }
                            }

                            totalData.push(subTotalData);
                        }
                        vm.calDatas = totalData;
                        vm.isInitCal = true;

                        if (totalData.join('') == "合计") {
                            return [];
                        }

                        var currentIndex = 0
                        //把合计缩进到最后一个
                        for (var i = 1; i < totalData.length; i++) {
                            if (totalData[i] != "") {
                                currentIndex = i - 1;
                                break;
                            }
                        }
                        totalData[currentIndex] = "合计";



                        return totalData;
                    }





                },
                getSubSummaries(param) {
                    if (vm.isSubInitCal) {
                        return vm.calSubDatas;
                    }
                    //合计总数据
                    if (vm.summaryColumnData.length > 0) {
                        var subAllTotalData = [];
                        var groupTotalData = [];

                        for (var i = 0; i < vm.formDesign.length; i++) {
                            for (var j = 0; j < vm.formDesign[i].controls.length; j++) {
                                var controlName = vm.formDesign[i].controls[j].baseProperty.controlName;
                                if (controlName == vm.subColTotal) {
                                    for (var k = 0; k < vm.formDesign[i].controls[j].controlProperty.select.sqlDataSource.length; k++) {
                                        groupTotalData.push(vm.formDesign[i].controls[j].controlProperty.select.sqlDataSource[k][vm.formDesign[i].controls[j].controlProperty.select.displayValue]);
                                    }
                                }
                            }
                        }

                        for (var z = 0; z < groupTotalData.length; z++) {
                            var searchData = JSLINQ(vm.tableData).where(function (item) {
                                return item[vm.subColTotal] == groupTotalData[z]
                            }).ToArray();

                            var totalData = [];
                            totalData.push("");
                            for (var i = 0; i < param.columns.length; i++) {
                                if (param.columns[i].property == vm.column_originConfig[0].name) {
                                    continue;
                                }
                                var subTotalData = "";

                                var current_Column = JSLINQ(vm.column_originConfig).where(function (item) {
                                    return item.name == param.columns[i].property
                                }).ToArray()[0];
                                if (current_Column) {
                                    if (current_Column.total != "") {
                                        subTotalData = vm.summaryColumnData[0][current_Column.name]
                                    }
                                }

                                totalData.push(subTotalData);
                            }

                            if (totalData.join('') == "") {
                                subAllTotalData.push({
                                    data: []
                                });
                            } else {
                                var currentSubIndex = 0;
                                debugger;
                                //把合计缩进到最后一个
                                for (var p = 1; p < totalData.length; p++) {
                                    if (totalData[p] != "") {
                                        currentSubIndex = p - 1;
                                        break;
                                    }
                                }
                                totalData[currentSubIndex] = groupTotalData[z] + "合计";


                                subAllTotalData.push({
                                    data: totalData
                                });
                            }
                        }
                        vm.calSubDatas = subAllTotalData;
                    } else {
                        var subAllTotalData = [];
                        var groupTotalData = [];

                        for (var i = 0; i < vm.formDesign.length; i++) {
                            for (var j = 0; j < vm.formDesign[i].controls.length; j++) {
                                var controlName = vm.formDesign[i].controls[j].baseProperty.controlName;
                                if (controlName == vm.subColTotal) {
                                    for (var k = 0; k < vm.formDesign[i].controls[j].controlProperty.select.sqlDataSource.length; k++) {
                                        groupTotalData.push(vm.formDesign[i].controls[j].controlProperty.select.sqlDataSource[k][vm.formDesign[i].controls[j].controlProperty.select.displayValue]);
                                    }
                                }
                            }
                        }

                        for (var z = 0; z < groupTotalData.length; z++) {
                            var searchData = JSLINQ(vm.tableData).where(function (item) {
                                return item[vm.subColTotal] == groupTotalData[z]
                            }).ToArray();

                            var totalData = [];
                            totalData.push("");
                            for (var i = 0; i < param.columns.length; i++) {
                                if (param.columns[i].property == vm.column_originConfig[0].name) {
                                    continue;
                                }
                                var subTotalData = "";

                                var current_Column = JSLINQ(vm.column_originConfig).where(function (item) {
                                    return item.name == param.columns[i].property
                                }).ToArray()[0];
                                if (current_Column) {
                                    if (current_Column.total != "") {
                                        //如果是合计类的
                                        if (current_Column.total.indexOf('sum') >= 0) {
                                            if (current_Column.total.indexOf('$') < 0) {
                                                //保留位数
                                                var fixNum = 0;
                                                if (current_Column.total.indexOf(',') >= 0) {
                                                    fixNum = parseInt(current_Column.total.split(',')[1]);
                                                }
                                                var totalNum = 0;
                                                for (var j = 0; j < searchData.length; j++) {
                                                    var currentNum = parseFloat(searchData[j][current_Column.name]);
                                                    if (isNaN(currentNum)) {
                                                        currentNum = 0;
                                                    }
                                                    totalNum += currentNum;
                                                }
                                                subTotalData = totalNum.toFixed(fixNum);
                                            } else {
                                                var sumPart = current_Column.total.split('$')[0];
                                                //保留位数
                                                var fixNum = 0;
                                                if (sumPart.indexOf(',') >= 0) {
                                                    fixNum = parseInt(sumPart.split(',')[1]);
                                                }
                                                var totalNum = 0;
                                                for (var j = 0; j < searchData.length; j++) {
                                                    var currentNum = parseFloat(searchData[j][current_Column.name]);
                                                    if (isNaN(currentNum)) {
                                                        currentNum = 0;
                                                    }
                                                    totalNum += currentNum;
                                                }
                                                subTotalData = totalNum.toFixed(fixNum);

                                                var divisorIndex = -1;
                                                for (var k = 0; k < param.columns.length; k++) {
                                                    if (param.columns[k].property == current_Column.total.split('$')[1]) {
                                                        divisorIndex = k;
                                                    }
                                                }
                                                subTotalData += "(" + (totalNum * 100.0 / totalData[divisorIndex]).toFixed(2) + "%)";
                                            }
                                        } else if (current_Column.total.indexOf('avg') >= 0) {
                                            //保留位数
                                            var fixNum = 0;
                                            if (current_Column.total.indexOf(',') >= 0) {
                                                fixNum = parseInt(current_Column.total.split(',')[1]);
                                            }
                                            var operData = current_Column.total.split(',')[0].substring(current_Column.total.split(',')[0].indexOf('(') + 1, current_Column.total.split(',')[0].indexOf(')'));
                                            var divisorCol = operData.split('/')[0];
                                            var dividendCol = operData.split('/')[1];
                                            var divisorIndex = 0,
                                                dividendIndex = 0;
                                            for (var k = 0; k < param.columns.length; k++) {
                                                if (param.columns[k].property == divisorCol) {
                                                    divisorIndex = k;
                                                }
                                                if (param.columns[k].property == dividendCol) {
                                                    dividendIndex = k;
                                                }
                                            }
                                            var totalResult = totalData[divisorIndex] / totalData[dividendIndex];
                                            if (current_Column.total.indexOf('%') >= 0) {
                                                totalResult = (totalResult * 100).toFixed(fixNum) + "%";
                                            } else {
                                                totalResult = totalResult.toFixed(fixNum)
                                            }
                                            subTotalData = totalResult;


                                            //var totalNum = 0;
                                            //for (var j = 0; j < vm.tableData.length; j++) {
                                            //    var currentNum = parseFloat(vm.tableData[j][current_Column.name]);
                                            //    if (isNaN(currentNum)) {
                                            //        currentNum = 0;
                                            //    }
                                            //    totalNum += currentNum;
                                            //}
                                            //if (vm.tableData.length > 0) {
                                            //    subTotalData = (totalNum / vm.tableData.length).toFixed(fixNum);
                                            //}
                                            //else {
                                            //    subTotalData = "0";
                                            //}
                                        }
                                    }
                                }

                                totalData.push(subTotalData);
                            }

                            if (totalData.join('') == "") {
                                subAllTotalData.push({
                                    data: []
                                });
                            } else {
                                var currentSubIndex = 0;
                                debugger;
                                //把合计缩进到最后一个
                                for (var p = 1; p < totalData.length; p++) {
                                    if (totalData[p] != "") {
                                        currentSubIndex = p - 1;
                                        break;
                                    }
                                }
                                totalData[currentSubIndex] = groupTotalData[z] + "合计";


                                subAllTotalData.push({
                                    data: totalData
                                });
                            }
                        }
                        vm.calSubDatas = subAllTotalData;
                    }

                    vm.isSubInitCal = true;

                },
                showSelectTreeWindow(colProperty, selValue, controlName, currentControl) {
                    var currentLayerNo = new Date().getTime();
                    var url = colProperty.select.url;
                    if (url.indexOf('?') < 0) {
                        url = url + "?t=1"
                    }
                    url += "&layerNo=" + currentLayerNo;
                    var selObj = JSLINQ(colProperty.select.sqlDataSource).where(function (item) {
                        return item[colProperty.select.hiddenValue] == selValue
                    }).ToArray();
                    var selName = "";
                    if (selObj.length > 0) {
                        selName = selObj[0][colProperty.select.displayValue].replace(/#/g, '');
                    }
                    url += "&selectName=" + selName;
                    url += "&selectValue=" + selValue;
                    url += "&selectArea=1";
                    url += "&selectKeyName=" + colProperty.select.hiddenValue;
                    url += "&selectKeyValue=" + colProperty.select.displayValue;
                    url += "&chooseType=" + colProperty.select.chooseType;
                    top.window[currentLayerNo] = window;
                    var layerIndex = top.layer.open({
                        type: 2,
                        title: '表单数据源',
                        anim: 5,
                        maxmin: true,
                        shadeClose: false,
                        area: ['80%', '80%'],
                        content: url,
                        cancel: function () { }
                    });
                    top.window[currentLayerNo + "_index"] = layerIndex;
                    vm.currentControlName = controlName;
                    vm.currentControl = currentControl;

                    //通过localstage传递所需要的参数
                    var treeSQL = '',
                        formSQL = '';
                    if (colProperty.select.treeSQL) {
                        treeSQL = colProperty.select.treeSQL;
                    }
                    if (colProperty.select.formSQL) {
                        formSQL = colProperty.select.formSQL;
                    }
                    if (url.toLowerCase().indexOf('tree') >= 0 && treeSQL != '') {
                        localStorage.setItem(currentLayerNo + "_treeSQL", treeSQL);
                        localStorage.setItem(currentLayerNo + "_treeSQLData", JSON.stringify(vm.formData));
                    }
                    if (formSQL != '') {
                        localStorage.setItem(currentLayerNo + "_formSQL", formSQL);
                        localStorage.setItem(currentLayerNo + "_formSQLData", JSON.stringify(vm.formData));
                    }
                },
                //提交选中树型窗口
                submitSelectTreeWindow(selectKeyValue) {
                    vm.isInitPage = false;
                    vm.formData[vm.currentControlName] = selectKeyValue;
                    var valueList = [];
                    if (vm.formData[vm.currentControlName] != undefined && vm.formData[vm.currentControlName] != "") {
                        for (var i = 0; i < vm.formData[vm.currentControlName].toString().split(',').length; i++) {
                            valueList.push("'" + vm.formData[vm.currentControlName].toString().split(',')[i] + "'")
                        }
                    }
                    var sql = "select * from (" + vm.currentControl.controlProperty.select.dataSource + ")t";
                    if (valueList.length > 0) {
                        sql += " where " + vm.currentControl.controlProperty.select.hiddenValue + " in (" + valueList.join(',') + ") ";
                        $.ajax({
                            url: "/SQLData/GetDataBySql",
                            async: false,
                            data: {
                                programId: localStorage.getItem("programId"),
                                sql: sql
                            },
                            type: "post",
                            dataType: 'json',
                            success: function (data) {
                                if (data.status == 200) {
                                    vm.$set(vm.currentControl.controlProperty.select, "sqlDataSource", data.data.ds);
                                    vm.$set(vm.currentControl.controlProperty.select, "originDataSource", data.data.ds);
                                    //绑定固定值
                                    vm.$set(vm.currentControl.controlProperty.select, "actualName", "");
                                    vm.$set(vm.currentControl.controlProperty.select, "actualName", JSLINQ(data.data.ds).select(function (item) {
                                        return item[vm.currentControl.controlProperty.select.displayValue]
                                    }).ToArray().join(','));
                                }
                            }
                        });
                    } else {
                        vm.$set(vm.currentControl.controlProperty.select, "actualName", "");
                    }
                    //if (vm.currentControl.controlProperty.select.change != "") {
                    //    vm.selectChange(vm.currentControl);
                    //}
                    //if (vm.currentControl.baseProperty.controlCallBack) {
                    //    var script = vm.currentControl.baseProperty.controlCallBack.replace(/\['/g, "vm.formData['");
                    //    script = script.replace(/\["/g, "vm.formData[\"");
                    //    eval(script);
                    //    vm.refreshInitActualName();
                    //}
                },
                //三个小点提交选中事件
                selectTableSubmit($event, col) {
                    if (window.event.keyCode == 13) {
                        vm.currentControlName = col.baseProperty.controlName;
                        vm.currentControl = col;
                        window.event.preventDefault();
                        var searchKey = $($event.target).val();
                        var searchParam = [];
                        for (var key in vm.currentClickRow) {
                            searchParam.push({
                                Key: key,
                                Value: vm.currentClickRow[key]
                            })
                        }
                        if (col.controlProperty.select.filterSQL) {
                            $.post("/SQLData/QueryFilterSQL", {
                                programId: localStorage.getItem("programId"),
                                sql: col.controlProperty.select.dataSource + " where " + col.controlProperty.select.filterSQL,
                                moduleUrl: col.controlProperty.select.url,
                                searchKey: searchKey,
                                sqlParam: searchParam
                            }, function (data) {
                                $($event.target).hide();
                                $($event.target).prev().children("input").css({
                                    opacity: 1
                                })
                                //单条数据
                                if (data.status == 200) {
                                    var selectKeyValue = data.data[0][col.controlProperty.select.hiddenValue];

                                    if (selectKeyValue == "") {
                                        vm.formData[vm.currentControlName] = null;
                                        vm.$set(col.controlProperty.select, "actualName", "");
                                    } else {
                                        vm.formData[col.baseProperty.controlName] = selectKeyValue;
                                        vm.$set(col.controlProperty.select, "actualName", data.data[0][col.controlProperty.select.displayValue]);
                                        vm.$set(col.controlProperty.select, "sqlDataSource", data.data);
                                    }

                                    if (col.controlProperty.select.change != "") {
                                        vm.selectChange(col);
                                    }
                                    if (col.baseProperty.controlCallBack) {
                                        var script = col.baseProperty.controlCallBack.replace(/\['/g, "vm.formData['");
                                        script = script.replace(/\["/g, "vm.formData[\"");
                                        eval(script);
                                        vm.refreshInitActualName();
                                    }
                                } else if (data.status == 201) {
                                    var currentLayerNo = new Date().getTime();
                                    var dbDetail = col.controlProperty.select;
                                    var url = dbDetail.url;
                                    if (url.indexOf('?') < 0) {
                                        url = url + "?t=1"
                                    }
                                    url += "&layerNo=" + currentLayerNo;
                                    var selValue = "";
                                    var selName = "";
                                    url += "&selectName=" + selName;
                                    url += "&selectValue=" + selValue;
                                    url += "&selectArea=1";
                                    url += "&selectKeyName=" + dbDetail.hiddenValue;
                                    url += "&selectKeyValue=" + dbDetail.displayValue;
                                    url += "&chooseType=" + dbDetail.chooseType;
                                    top.window[currentLayerNo] = window;

                                    var layerIndex = top.layer.open({
                                        type: 2,
                                        title: '表单数据源',
                                        anim: 5,
                                        maxmin: true,
                                        shadeClose: false,
                                        area: ['80%', '80%'],
                                        content: url,
                                        cancel: function () { }
                                    });
                                    //通过localstage传递所需要的参数
                                    var treeSQL = '',
                                        filterSQL = '';
                                    if (dbDetail.treeSQL) {
                                        treeSQL = dbDetail.treeSQL;
                                    }
                                    if (dbDetail.filterSQL) {
                                        filterSQL = dbDetail.filterSQL;
                                        String.prototype.replaceAll = function (s1, s2) {
                                            return this.replace(new RegExp(s1, "gm"), s2);
                                        }
                                        filterSQL = filterSQL.replaceAll("@searchKey", "'%'+'" + searchKey + "'+'%'");

                                    }
                                    localStorage.setItem(currentLayerNo + "_treeSQLData", JSON.stringify(col));
                                    if (url.toLowerCase().indexOf('tree') >= 0 && treeSQL != '') {
                                        localStorage.setItem(currentLayerNo + "_treeSQL", treeSQL);
                                    }
                                    if (filterSQL != '') {
                                        localStorage.setItem(currentLayerNo + "_filterSQL", filterSQL);
                                        localStorage.setItem(currentLayerNo + "_filterSQLData", JSON.stringify(col));
                                    }
                                    top.window[currentLayerNo + "_index"] = layerIndex;
                                } else {
                                    layer.msg(data.msg);
                                }
                            }, "json");
                        }
                        //vm.currentClickCol
                        //vm.currentClickRow
                    }
                },
                //三个小点显示事件
                showSelectTableSubmit(obj) {
                    debugger;
                    var domCurrent = $(obj).parent().next();
                    domCurrent.val($(obj).val());
                    if ($(obj).css("background")) {
                        domCurrent.css({
                            background: $(obj).css("background")
                        });
                    }
                    $(obj).css({
                        opacity: 0
                    });
                    domCurrent.show();
                    domCurrent.focus();
                    domCurrent.unbind("blur");
                    domCurrent.blur(function () {
                        domCurrent.hide();
                        $(obj).css({
                            opacity: 1
                        });
                    });
                },
                getSYDefaultValue(funcName) {
                    if (funcName.indexOf("getdate()") >= 0) {
                        var date;
                        if (funcName == "getdate()") {
                            date = new Date();
                        } else {
                            date = new Date();
                            Date.prototype.DateAdd = function (strInterval, Number) {
                                var dtTmp = this;
                                switch (strInterval) {
                                    case 's':
                                        return new Date(Date.parse(dtTmp) + (1000 * Number));
                                    case 'n':
                                        return new Date(Date.parse(dtTmp) + (60000 * Number));
                                    case 'h':
                                        return new Date(Date.parse(dtTmp) + (3600000 * Number));
                                    case 'd':
                                        return new Date(Date.parse(dtTmp) + (86400000 * Number));
                                    case 'w':
                                        return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
                                    case 'q':
                                        return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number * 3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
                                    case 'm':
                                        return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
                                    case 'y':
                                        return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
                                }
                            }
                            var addFun = funcName.split('.')[1];
                            eval("date=date." + addFun);
                        }
                        var seperator1 = "-";
                        var seperator2 = ":";
                        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                        var strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
                            " " + date.getHours() + seperator2 + date.getMinutes() +
                            seperator2 + date.getSeconds();
                        return currentdate;
                    } else if (funcName.indexOf("@") >= 0) {
                        if (funcName == '@P_UserID' || funcName == '@P_UserCode') {
                            return {
                                P_UserID: APP.getUserInfo().UserID,
                                P_UserName: APP.getUserInfo().UserName,
                                P_UserCode: APP.getUserInfo().UserCode
                            }
                        }
                    }
                    else {
                        return eval(funcName);
                    }
                },
                //change显示列操作
                checkShowColumn() {
                    vm.$refs.operMenu.show();

                    localStorage.setItem(tableConfig.objName + "_report", JSON.stringify(vm.showColumns));

                    vm.searchReport();
                },
                isShowCheckCol(colName) {
                    // if (JSLINQ(vm.showColumns).where(function(item) {
                    //         return item == colName
                    //     }).ToArray().length > 0) {
                    //     return true;
                    // } else {
                    //     return false;
                    // }
                    return true;
                },
                rowSpanMethod(rowObj) {
                    if (rowObj) {
                        if (vm.spanMethodFunc) {
                            var spanObj = undefined;
                            var scriptFun = " function fun(){ " + vm.spanMethodFunc + "  }  ";
                            scriptFun += "spanObj = fun()  ";
                            eval(scriptFun);
                            if (spanObj) {
                                return spanObj;
                            }

                        }
                    }

                },
                initChart() {
                    for (var i = 0; i < vm.chartConfig.length; i++) {
                        var chartId = "chart" + i.toString();
                        if ($("#" + chartId).length == 0) {
                            $("#app").append('<div id="' + chartId + '" style="width:' + vm.chartConfig[i].width + 'px;height:' + vm.chartConfig[i].height + 'px"></div>');
                        }
                        layer.open({
                            type: 1,
                            title: vm.chartConfig[i].title,
                            anim: 5,
                            shadeClose: false,
                            area: [vm.chartConfig[i].width, vm.chartConfig[i].height],
                            content: $("#" + chartId),
                            cancel: function () { }
                        });

                    }
                },
                openSearch: function () {
                    var that = this;
                    that.showSearch = true;
                },
                searchData: function () {
                    var that = this;
                    that.showSearch = false;

                    that.getDataList();
                },
                openSelect: function (row, index) {
                    var that = this;

                    if (row.baseProperty.isReadOnly) return;
                    editIndex = index;

                    var sql = "select * from (" + row.controlProperty.select.dataSource + ")t";
                    var filter = row.controlProperty.select.formSQL + '';

                    if (filter) {
                        for (var key in that.formData) {
                            var value = "'" + that.formData[key] + "'";
                            var filterEvent = new Function("filter.replace(/" + "@" + key + "/g,value)");
                            filterEvent();
                        }
                        sql += filter ? (' where ' + filter) : '';
                    }




                    if (row.controlProperty.select.type == 1) {
                        that.selectColumns = [];
                        that.selectValueKey = row.controlProperty.select.displayValue;
                        that.selectRealKey = row.controlProperty.select.hiddenValue;
                        that.showSelect = true;
                        that.selectLoading = true;

                        $.ajax({
                            url: APP.serverIP() + "/SQLData/GetDataBySql",
                            async: true,
                            data: {
                                sql: sql
                            },
                            type: "post",
                            dataType: 'json',
                            success: function (res) {
                                if (res.status == 200) {
                                    var data = res.data;

                                    that.selectColumns = data.ds;
                                    that.selectLoading = false;

                                }
                            }
                        });

                    }
                },
                confirmSelect: function (value, index) {
                    var that = this;
                    that.searchList[editIndex].baseProperty.showValue = that.selectColumns[index][that.selectValueKey];
                    that.searchList[editIndex].baseProperty.value = that.selectColumns[index][that.selectRealKey];
                    that.formData[that.searchList[editIndex].baseProperty.controlName] = that.selectColumns[index][that.selectRealKey];

                    that.showSelect = false;
                    that.selectColumns = [];
                },
                cancelSelect: function () {
                    var that = this;
                    that.showSelect = false;
                    that.selectColumns = [];
                },
                openDate: function (row, index) {
                    var that = this;
                    if (row.baseProperty.isReadOnly) {
                        return;
                    }
                    editIndex = index;
                    if (row.baseProperty.showValue) {
                        that.currentDate = new Date(row.baseProperty.showValue);
                    } else {
                        that.currentDate = new Date();
                    }

                    that.showDate = true;

                },
                confirmDate: function (value) {
                    var that = this;
                    that.searchList[editIndex].baseProperty.value = APP.getFormatDate(value).split(' ')[0];
                    that.formData[that.searchList[editIndex].baseProperty.controlName] = APP.getFormatDate(value).split(' ')[0];

                    that.searchList[editIndex].baseProperty.showValue = APP.getFormatDate(value).split(' ')[0];
                    that.showDate = false;
                },
                cancelDate: function (value) {
                    var that = this;
                    that.searchList[editIndex].baseProperty.value = '';
                    that.formData[that.searchList[editIndex].baseProperty.controlName] = '';
                    that.searchList[editIndex].baseProperty.showValue = '';
                    that.showDate = false;
                },
                //图片，视频查看
                openMedia(sopObj, type) {
                    if (type == 1) {
                        vm.showImg = true;
                        var sopObjList = [];
                        for (var i = 0; i < sopObj.split(',').length; i++) {
                            sopObjList.push(APP.serverIP() + sopObj.split(',')[i]);
                        }
                        vm.showImgList = sopObjList;
                    } else if (type == 2) {
                        var videoPath = APP.serverIP() + sopObj;
                        api.openWin({
                            name: 'play',
                            url: '../tool/videoPlayer.html',
                            slidBackEnabled: true,
                            pageParam: {
                                videoPath: videoPath
                            }
                        })
                    } else if (type == 3) {
                        var officePath = APP.serverIP() + sopObj;
                        api.download({
                            url: APP.serverIP() + sopObj,
                            report: true
                        }, function (downloadRet, err) {
                            console.log(JSON.stringify(downloadRet))
                            if (err) {
                                api.hideProgress();
                                api.toast({
                                    msg: '下载失败请重试!',
                                    duration: 2000
                                })
                            } else if (downloadRet.state == 0) {
                                api.showProgress({
                                    title: downloadRet.percent + '%',
                                    modal: false
                                });
                            } else if (downloadRet.state == 1) {
                                api.hideProgress();

                                docReader.open({
                                    path: 'file://' + downloadRet.savePath,
                                }, function (ret, err) {
                                    if (ret.status) {
                                    } else {
                                        api.toast({
                                            msg: '文档打开失败' + JSON.stringify(err),
                                            duration: 2000
                                        })
                                    }
                                });
                            }
                        })
                        // office.open({
                        //     rect: { x: 0, y: 0, w: 'auto', h: 'auto' },
                        //     url: officePath, //或者widget://文档
                        //     // topBarColor: '#3394EC',
                        //     // title: '标题',
                        //     fileType: sopObj.split('.')[sopObj.split('.').length - 1]
                        // },
                        //     function (ret, err) {
                        //     });
                    }
                },
                onClickLeft: function () {
                    // api.setScreenOrientation({
                    //     orientation: 'portrait_up'
                    // })
                    api.closeWin();
                }
            }
        })







    };



    var tableConfig = {
        objName: '',
        //设置配置
        set: function (options) {
            vm.sql = options.sql;
            vm.rowClassCol = options.rowClassCol;
            vm.colClassCol = options.colClassCol;
            vm.searchCallBack = options.searchCallBack;


            vm.spanMethodFunc = options.spanMethod;

            if (options.chartConfig) {
                vm.chartConfig = JSON.parse(options.chartConfig);
                vm.initChart();
            }

            if (vm.spanMethodFunc) {
                $.appendNum = 500;
            } else {
                $.appendNum = 15;
            }


            vm.openLoading();
            if (options.childFormList == null) {
                options.childFormList = [];
            }
            vm.childFormList = options.childFormList;

            var searchList = options.formDesign;
            var x = 0;
            for (var i in searchList) {
                searchList[i].baseProperty.value = '';
                searchList[i].baseProperty.showValue = '';
                vm.formData[searchList[i].baseProperty.controlName] = '';
                if (searchList[i].baseProperty.defaultValue) {
                    //console.log(searchList[i].baseProperty.defaultValue)
                    //console.log(vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue))
                    searchList[i].baseProperty.value = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);
                    searchList[i].baseProperty.showValue = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);
                    //vm.formData[searchList[i].baseProperty.controlName] = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);

                    if (searchList[i].baseProperty.defaultValue && searchList[i].baseProperty.defaultValue.indexOf('@') < 0) {
                        vm.formData[searchList[i].baseProperty.controlName] = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);
                    }
                    else if (searchList[i].baseProperty.defaultValue && searchList[i].baseProperty.defaultValue.indexOf('@') >= 0) {
                        var userInfo = vm.getSYDefaultValue(searchList[i].baseProperty.defaultValue);
                        if (searchList[i].baseProperty.defaultValue && searchList[i].baseProperty.defaultValue.indexOf('Code') >= 0) {
                            vm.formData[searchList[i].baseProperty.controlName] = userInfo.P_UserCode;
                        }
                        else {
                            vm.formData[searchList[i].baseProperty.controlName] = userInfo.P_UserID;
                        }
                    }
                    else {
                        vm.formData[searchList[i].baseProperty.controlName] = "";
                    }
                }

                if (searchList[i].baseProperty.isRequired) {
                    x = 1;
                }
            }
            vm.searchList = searchList;


            //子报表自动查询
            //验证必填项
            var valitedResult = vm.valitedRequired();
            var isSuccess = false;
            if (valitedResult.status == 200) {
                isSuccess = true;
            }


            vm.$nextTick(() => {
                //vm.tableHeight = 500; //document.getElementsByClassName("report-table")[0].offsetHeight;
                if (api.pageParam.subReport || isSuccess) {
                    vm.openLoading();
                    vm.searchReport();
                }
            })


        },
        //初始化配置
        initConfig: function (objName) {
            if (objName == undefined) {
                return;
            }
            //console.log(objName)
            tableConfig.objName = objName;
            setTimeout(function () {
                $.ajax({
                    url: APP.serverIP() + "/ReportList/GetDataByName",
                    async: false,
                    data: {
                        objName: objName
                    },
                    type: "post",
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 200) {
                            var data = res;
                            tableConfig.set({
                                sql: data.data.ds[0]["sql"],
                                formDesign: JSON.parse(data.data.ds[0]["searchDesignConfig"]),
                                rowClassCol: data.data.ds[0]["rowClassCol"],
                                colClassCol: data.data.ds[0]["colClassCol"],
                                searchCallBack: data.data.ds[0]["searchCallBack"],
                                spanMethod: data.data.ds[0]["spanMethod"],
                                chartConfig: data.data.ds[0]["chartConfig"]
                            });

                        }
                    }
                });

            }, 200);

        }
    }
</script>

</html>
